<template>
	<el-dialog v-model="visible" title="详情">
		<!-- 基本信息-->
		<el-descriptions size="default" :column="1" label-class-name="el-descriptions-item-label-class" border>
			<el-descriptions-item label="名称">{{ dataForm.taskName }}</el-descriptions-item>
			<el-descriptions-item label="执行器">{{ actuatorName }}</el-descriptions-item>

			<el-descriptions-item label="调度类型">
				<span v-if="dataForm.taskType == '2'"> 一次性全量同步 </span>
				<span v-if="dataForm.taskType == '3'"> 周期性增量 </span>
			</el-descriptions-item>
			<el-descriptions-item v-if="dataForm.taskType == '3'" label="cron表达式">{{ dataForm.cron }}</el-descriptions-item>

			<!-- <el-descriptions-item label="构建内容"> -->
			<!-- <div style="height: 400px; width: 100%"> -->
			<!-- </div> -->
			<!-- </el-descriptions-item> -->
		</el-descriptions>
		<InfoJson ref="infoJsonRef" style="height: 400px; width: 100%"></InfoJson>
	</el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref, onMounted, nextTick } from 'vue'
import { useAccessApi } from '@/api/data-integrate/access'
import { listDatabase } from '@/api/data-integrate/database'
import { actuatorDataList } from '@/api/task-scheduling'
import InfoJson from './info-json.vue'
// import DataStudioJson from '../../task-scheduling/production/data-studio-json.vue'

const visible = ref(false)
const dataForm = reactive({
	taskName: '',
	description: '',
	projectId: '',
	sourceDatabaseId: '',
	sourceDatabase: {},
	taskType: '',
	cron: '',
	databases: [],
	includeOrExclude: 1,
	sourceTables: [],
	sourceSelectedTables: [],
	accessMode: 1,
	targetDatabaseId: '',
	targetDatabase: {},
	targetOnlyCreate: false,
	targetSyncExit: true,
	targetDropTable: true,
	targetDataSync: false,
	targetIndexCreate: false,
	targetLowerCase: false,
	targetUpperCase: false,
	targetAutoIncrement: false,
	batchSize: 1000,
	tableNameMapper: [],
	columnNameMapper: []
})

const actuatorData = ref([])
const actuatorName = ref('')
const infoJsonRef = ref()

const isInfoVisible = ref(false)

onMounted(() => {
	listDatabase().then(res => {
		dataForm.databases = res.data
	})
})

const init = async (id?: number) => {
	visible.value = true
	dataForm.id = ''

	// 获取执行器列表
	await actuatorDataList().then((res: any) => {
		actuatorData.value = res.data
	})

	if (id) {
		getAccess(id)
	}
}

const getAccess = (id: number) => {
	useAccessApi(id).then(res => {
		Object.assign(dataForm, res.data)

		if (dataForm.executeId) {
			actuatorData.value.find(item => {
				if (item.id == dataForm.executeId) {
					actuatorName.value = item.title + '[' + item.appName + ']'
				}
			})
		}

		if (dataForm.sourceDatabaseId) {
			dataForm.sourceDatabase = dataForm.databases.find(item => {
				return item.id == dataForm.sourceDatabaseId
			})
		}
		if (dataForm.targetDatabaseId) {
			dataForm.targetDatabase = dataForm.databases.find(item => {
				return item.id == dataForm.targetDatabaseId
			})
		}

		if (dataForm.dataxJson) {
			// const data = JSON.parse(dataForm.dataxJson)

			// data.job.content[0].reader.parameter.connection[0].querySql = []
			// data.job.content[0].reader.parameter.connection[0].querySql.push(
			// 	"select \n    '12330109754405020K'||'-'||a.rec_sn as prm_key, -- 主键\n    '12330109754405020K' as mdc_org_cd, -- 医疗机构代码\n    '浙江萧山医院' as mdc_org_nm, -- 医疗机构名称\n    a.rec_sn as oprt_no, -- 手术流水号\n    '' as elctrnc_apl_no, -- 电子申请单编号\n    '' as otpt_emg_no, -- 门（急）诊号\n    a.ipid as inhos_no, -- 住院号\n    a.pid as pid, -- 患者id\n    --to_date(a.operation_time,'yyyy-mm-dd hh24:mi:ss') \n\t\tto_timestamp(a.operation_time,'yyyymmddhh24miss')::timestamp as oprt_dt_tm, -- 手术操作日期时间\n    --to_date(a.operation_start_time,'yyyy-mm-dd hh24:mi:ss') \n\t\tto_timestamp(a.operation_start_time,'yyyymmddhh24miss')::timestamp as oprt_strt_dt_tm, -- 手术开始日期时间\n    --to_date(a.operation_end_time,'yyyy-mm-dd hh24:mi:ss') \n\t\tto_timestamp(a.operation_end_time,'yyyymmddhh24miss')::timestamp as oprt_end_dt_tm, -- 手术结束日期时间\n    a.dept_code as oprt_dpt_cd, -- 手术科室代码\n    a.dept_name as oprt_dpt_nm, -- 手术科室名称\n    a.operation_doctor_id as oprt_dct_cd, -- 手术医生工号\n    a.operation_doctor as oprt_dct_nm, -- 手术医生姓名\n    a.operation_room_code as oprt_room_cd, -- 手术室编号\n    a.operation_order as oprt_pltfm_cd, -- 手术台号\n    a.operation_code as oprt_cd, -- 手术代码\n    a.operation_name as oprt_nm, -- 手术名称\n    '' as main_oprt_flg, -- 主手术标识\n    case when a.OPERATION_LEVEL in ('Ⅰ类手术','一级') then '1'\n         when a.OPERATION_LEVEL in ('Ⅱ类手术','二级') then '2'\n         when a.OPERATION_LEVEL in ('三级','Ⅲ类手术') then '3'\n         when a.OPERATION_LEVEL in ('Ⅳ类手术','四级') then '4'\n    else '9' end as oprt_lvl_cd, -- 手术级别代码\n    case when a.OPERATION_LEVEL in ('Ⅰ类手术','一级') then '一级手术'\n         when a.OPERATION_LEVEL in ('Ⅱ类手术','二级') then '二级手术'\n         when a.OPERATION_LEVEL in ('三级','Ⅲ类手术') then '三级手术'\n         when a.OPERATION_LEVEL in ('Ⅳ类手术','四级') then '四级手术'\n    else '其他手术' end as oprt_lvl_nm, -- 手术级别名称\n    '' as oprt_prt_cd, -- 手术及操作部位代码\n    '' as oprt_prt_nm, -- 手术及操作部位名称\n    '' as oprt_pstn_cd, -- 手术体位代码\n    '' as oprt_pstn_nm, -- 手术体位名称\n    case when a.cut_grade_name in ('0类切口') then '1'\n         when a.cut_grade_name in ('Ⅰ(介入)','Ⅰ类切口') then '2'\n         when a.cut_grade_name in ('Ⅱ类切口') then '3'\n         when a.cut_grade_name in ('Ⅲ类切口') then '4'\n    else '9' end as oprt_incs_cgy_cd, -- 手术切口类别代码\n    case when a.cut_grade_name in ('0类切口') then '0类切口'\n         when a.cut_grade_name in ('Ⅰ(介入)','Ⅰ类切口') then 'Ⅰ类切口'\n         when a.cut_grade_name in ('Ⅱ类切口') then 'Ⅱ类切口'\n         when a.cut_grade_name in ('Ⅲ类切口') then 'Ⅲ类切口'\n    else '其他' end as oprt_incs_cgy_nm, -- 手术切口类别名称\n    '' as poprt_dos, -- 术前用药\n    '' as intoprt_dos, -- 术中用药\n    '' as oprt_hst_flg, -- 手术史标志\n    '' as wgt, -- 体重(kg)\n    '' as abo_cd, -- abo血型代码\n    '' as abo_nm, -- abo血型名称\n    '' as rh_cd, -- rh血型代码\n    '' as rh_nm, -- rh血型名称\n    '' as poprt_diag_cd, -- 术前诊断编码\n    '' as poprt_diag_nm, -- 术前诊断名称\n    '' as oprt_aftr_diag_cd, -- 术后诊断代码\n    '' as oprt_aftr_diag_nm, -- 术后诊断名称\n    '' as day_oprt_flg, -- 日间手术标志\n    '' as oprt_tp_cd, -- 手术类型代码\n    '' as oprt_tp_nm, -- 手术类型名称\n    '' as oprt_prcs_dscpt, -- 手术过程描述\n    '' as oprt_way_dscpt, -- 操作方法描述\n    '' as oprt_tms, -- 操作次数\n    case when a.heal_grade like '%甲%' then '1'\n         when a.heal_grade like '%乙%' then '2'\n         when a.heal_grade like '%丙%' then '3' \n    else '9' end as oprt_incs_heal_lvl_cd, -- 手术切口愈合等级代码\n    case when a.heal_grade like '%甲%' then '甲'\n         when a.heal_grade like '%乙%' then '乙'\n         when a.heal_grade like '%丙%' then '丙' \n    else '其他' end as oprt_incs_heal_lvl_nm, -- 手术切口愈合等级名称\n    '' as oprt_cplct_flg, -- 手术并发症标志\n    '' as oprt_cplct_dtl_dscpt, -- 手术并发症详细描述\n    '' as oprt_cmplct_flg, -- 手术合并症标识\n    '' as oprt_cmplct_dscpt, -- 手术合并症描述\n    '' as drng_flg, -- 引流标志\n    '' as drng_mtrl_nm, -- 引流材料名称\n    '' as drng_mtrl_qty, -- 引流材料数目\n    '' as plc_prt, -- 放置部位\n    '' as hmhg_vlu, -- 出血量(ml)\n    '' as intoprt_trsfs_itm, -- 术中输液项目\n    '' as trsfs_vlu, -- 输液量(ml)\n    '' as intvt_mtrl_nm, -- 介入物名称\n    '' as skin_dsinfct_dscpt, -- 皮肤消毒描述\n    a.assistant_i_code as fst_oprt_asstnt_cd, -- 第一手术助理医生工号\n    a.assistant_ii_code as scd_oprt_asstnt_cd, -- 第二手术助理医生工号\n    a.assistant_iii_code as tdl_oprt_asstnt_dct_, -- 第三手术助理医生工号\n    a.assistant_iv_code as fthl_oprt_asstnt_dct, -- 第四手术助理医生工号\n    case when a.anesthesia like '%全%' and a.anesthesia like '%+%' then '4'\n         when a.anesthesia like '%全%' then '1' \n    else '3' end as aths_way_cd, -- 麻醉方法代码\n    case when a.anesthesia like '%全%' and a.anesthesia like '%+%' then '复合麻醉'\n         when a.anesthesia like '%全%' then '全身麻醉' \n    else '局部麻醉' end as aths_way_nm, -- 麻醉方法名称\n    a.anesthesia_doctor_code as aths_dct_cd, -- 麻醉医生工号\n    a.anesthesia_doctor as aths_dct_nm, -- 麻醉医生姓名\n    '' as scd_aths_dct_cd, -- 第二麻醉医生工号\n    '' as tdl_aths_dct_cd, -- 第三麻醉医生工号\n    '' as fst_aths_asstnt_dct_cd, -- 第一麻醉助理医生工号\n    '' as scd_aths_asstnt_dct_cd, -- 第二麻醉助理医生工号\n    '' as tdl_aths_asstnt_dct_cd, -- 第三麻醉助理医生工号\n    '' as fthl_aths_asstnt_dct_cd, -- 第四麻醉助理医生工号\n    a.circuit_nurse_code as fst_cct_nus_cd, -- 第一巡回护士工号\n    '' as scd_cct_nus_cd, -- 第二巡回护士工号\n    '' as fst_instrmt_nus_cd, -- 第一器械护士工号\n    '' as scd_instrmt_nus_cd, -- 第二器械护士工号\n    '' as tdl_instrmt_nus_cd, -- 第三器械护士工号\n    '' as elctv_oprt_flg, -- 择期手术标志\n    '' as infct_flg, -- 感染标识\n    --to_date(a.create_time,'yyyy-mm-dd hh24:mi:ss') \n\t\tto_timestamp(a.operation_time,'yyyymmddhh24miss')::timestamp as crt_tm, -- 创建时间\n    a.creator as crt_stff_cd, -- 创建职工工号\n    a.creator_name as crt_stff_nm, -- 创建职工姓名\n    --to_date(a.modify_time,'yyyy-mm-dd hh24:mi:ss') \n\t\tto_timestamp(a.modify_time,'yyyymmddhh24miss')::timestamp as upd_dt, -- 更新日期\n    '12330109754405020K' as upd_mdc_org_cd, -- 更新医疗机构代码\n    '浙江萧山医院' as upd_mdc_org_nm, -- 更新医疗机构名称\n    '' as upd_stff_cd, -- 更新职工工号\n    null as upd_stff_nm, -- 更新职工姓名\n    0 as invld_flg -- 作废标识\nfrom emr.operation_info_rec a  where  \noperation_time is not \t null   and operation_time > to_char((current_date - INTERVAL '5 day' ) , 'yyyy-MM-dd hh24:MI:SS')             \n                "
			// )
			// dataForm.dataxJson = JSON.stringify(data)
			// infoJsonRef.value.setEditorValue(JSON.stringify(data))
			infoJsonRef.value.setEditorValue(dataForm.dataxJson)
		}
	})
}

defineExpose({
	init
})
</script>

<style scoped>
.tip-content {
	font-size: 14px;
}
</style>
